*--------------------------------------------------------------; * Estimates the mean or total from a systematic random sample ; * using the successive difference variance estimator. ; *--------------------------------------------------------------; %macro est_sys(sample=,setup=,npop=,n=,response=,param=,fpc=); %if %length(&sample) = 0 %then %let sample = %str(sample); %if %length(&npop) = 0 %then %let npop = %str(npop); data temp_; set &sample( keep = &response ); y_ = lag(&response); run; data temp_; set temp_; diff_ = &response - y_; sq_ = diff_**2; proc means data = temp_ noprint; var sq_ &response; output out = est_ mean = s2d_ ybar_ n = ndiffs_ nobs_; run; data est_; %if %length(&setup) > 0 %then %do; merge &setup est_; %end; %else %do; set est_; %end; mu_hat_ = ybar_; %if %length(&fpc) = 0 %then %do; var_mu_ = ((&npop-nobs_)/&npop)*s2d_/(2*(nobs_)); std_mu_ = sqrt(var_mu_); bnd_mu_ = 2*std_mu_; tau_hat_ = &npop*ybar_; var_tau = &npop**2*var_mu_; std_tau_ = &npop*std_mu_; bnd_tau_ = 2*std_tau_; keep mu_hat_ tau_hat_ std_mu_ std_tau_ bnd_mu_ bnd_tau_ s2d_ ndiffs_; %end; %else %do; var_mu_ = s2d_/(nobs_); std_mu_ = sqrt(var_mu_); bnd_mu_ = 2*std_mu_; keep mu_hat_ std_mu_ bnd_mu_ s2d_ ndiffs_; %end; %if %index(%upcase(¶m),MEAN) > 0 %then %do; proc print data = est_ noobs split='*'; label mu_hat_ = 'Estimate'; label std_mu_ = 'Standard*Error'; label bnd_mu_ = 'Bound'; label s2d_ = 's(d)^2'; label ndiffs_ = 'Actual*Differences'; title1 "Estimate of the Population Mean"; title2 "Systematic Sampling Design"; title3 "(Successive Difference Estimator)"; title4 "Response Variable = &response"; var mu_hat_ std_mu_ bnd_mu_ s2d_ ndiffs_; %end; %if %index(%upcase(¶m),TOTAL) > 0 %then %do; proc print data = est_ noobs split='*'; label tau_hat_ = 'Estimate'; label std_tau_ = 'Standard*Error'; label bnd_tau_ = 'Bound'; label s2d_ = 's(d)^2'; label ndiffs_ = 'Actual*Differences'; title1 "Estimate of the Population Total"; title2 "Systematic Sampling Design"; title3 "(Successive Difference Estimator)"; title4 "Response Variable = &response"; var tau_hat_ std_tau_ bnd_tau_ s2d_ ndiffs_; %end; run; title; %mend est_sys;